package day230412;

import java.util.Scanner;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/4/13 15:21
 * MP3 光标位置
 */
public class Main02 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String numberOfSongs = scan.nextLine();
        String operation = scan.nextLine();
        playMP3(numberOfSongs, operation);
        scan.close();
    }

    // 模拟 MP3 光标位置
    private static void playMP3(String numberOfSong, String operation) {
        int numberOfSongs = Integer.parseInt(numberOfSong);
        int location = 1; // 指向每一页的初始位置
        int mouse = 1; // 光标位置
        char[] operations = operation.toCharArray(); // 操作序列
        if (numberOfSongs <= 4) {
            // 不需要翻页的情况
            for (int i = 0; i < operations.length; i++) {
                if (mouse == 1 && operations[i] == 'U') {
                    // 第一首往前
                    mouse = numberOfSongs;
                } else if (mouse == numberOfSongs && operations[i] == 'D') {
                    // 最后一首往后
                    mouse = 1;
                } else {
                    // 处理一般情况
                    if (operations[i] == 'U') {
                        mouse--;
                    }
                    if (operations[i] == 'D') {
                        mouse++;
                    }
                }
            }
            // 打印当前页歌曲和光标位置
            for (int i = 1; i <= numberOfSongs - 1; i++) {
                System.out.print(i + " ");
            }
            System.out.println(numberOfSongs);
            System.out.println(mouse);
        } else {
            // 需要翻页的情况
            for (int i = 0; i < operations.length; i++) {
                if (location == 1 && mouse == 1 && operations[i] == 'U') {
                    // 处于第一页的第一首歌曲的情况下往前
                    location = numberOfSongs - 3;
                    mouse = numberOfSongs;
                } else  if (location == numberOfSongs - 3 && mouse == numberOfSongs && operations[i] == 'D') {
                    // 处于最后一页的最后一首歌曲的情况下往后
                    location = 1;
                    mouse = 1;
                } else if (location != 1 && location == mouse && operations[i] == 'U') {
                    // 不是第一页, 屏幕处于当前页第一首歌曲的时候, 往前
                    location--;
                    mouse--;
                } else if (location != numberOfSongs - 3 && mouse == location + 3 && operations[i] == 'D') {
                    // 不是最后一页, 屏幕处于当前最后一首歌曲, 往后
                    location++;
                    mouse++;
                } else {
                    // 一般情况不需要翻页, 只需要移动光标
                    if (operations[i] == 'U') {
                        mouse--;
                    }
                    if (operations[i] == 'D') {
                        mouse++;
                    }
                }
            }
            // 打印当前页歌曲和光标位置
            for (int i = location; i < location + 3; i++) {
                System.out.print(i + " ");
            }
            System.out.println(location + 3);
            System.out.println(mouse);
        }
    }
}
